//
//  ListenTestTableViewCell.m
//  xpkc
//
//  Created by TopSage iOS on 14-8-18.
//  Copyright (c) 2014年 wanmeizty. All rights reserved.
//

#import "ListenTestTableViewCell.h"
#define kSubTitleFont [UIFont systemFontOfSize:10.0f]
@implementation ListenTestTableViewCell
{
	UIView *_starBaseView;
}
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
        [self creatCell];
    }
    return self;
}
-(void)creatCell{
    /**
     左侧标题
     */
    _left_image=[[UIImageView alloc] initWithFrame:RECT(12, 12, 118, 70)];
    /**
     题目
     */
	_title_Label=[[MyLabel alloc]initWithFrame:RECT(_left_image.frame.origin.x+127, 13, SCREEN_WIDTH-150, 43)];
    _title_Label.backgroundColor=CCOLOR;
    _title_Label.font = [UIFont systemFontOfSize:11.0f];
	[_title_Label setVerticalAlignment:VerticalAlignmentTop];
	_title_Label.textColor = [UIColor darkGrayColor];
    _title_Label.numberOfLines=3;
	
    /**
     讲师
     */
    _name_Label=[[UILabel alloc]initWithFrame:RECT(_left_image.frame.origin.x+127, _title_Label.frame.origin.y+40, SCREEN_WIDTH-130, 12)];
    _name_Label.backgroundColor=CCOLOR;
	_name_Label.font=kSubTitleFont;
    _name_Label.textColor = [UIColor darkGrayColor];
    /**
     名师姓名
     */
    _teacher_Label=[[UILabel alloc]initWithFrame:RECT(_left_image.frame.origin.x+158, _title_Label.frame.origin.y+40, SCREEN_WIDTH-130, 12)];
    _teacher_Label.backgroundColor=CCOLOR;
    _teacher_Label.font=kSubTitleFont;
    _teacher_Label.numberOfLines=3;
	_teacher_Label.textColor= [UIColor darkGrayColor];
	/**
	 时长名字
	 */
	_timeName_Label = [[UILabel alloc]init];
	_timeName_Label.frame = RECT(_left_image.frame.origin.x+220, _title_Label.frame.origin.y+40, SCREEN_WIDTH-130, 12);
	_timeName_Label.font = kSubTitleFont;
	_timeName_Label.text = @"时长：";
	_timeName_Label.textColor = [UIColor darkGrayColor];
	/**
	 时长
	 */
	_time_Label = [[UILabel alloc]init];
	_time_Label.frame = RECT(_left_image.frame.origin.x+250, _title_Label.frame.origin.y+40, SCREEN_WIDTH-130, 12);
	_time_Label.font = kSubTitleFont;
//	_time_Label.text = @"24分钟";
	_time_Label.textColor = [UIColor darkGrayColor];
	/**
	 星星
	 */
	_starBaseView = [[UIView alloc]init];
	_starBaseView.frame = CGRectMake(_left_image.frame.origin.x+127,  _title_Label.frame.origin.y+56, 58, 10);
	for (int i = 0; i<5; i++) {
		UIImageView *starImageView = [[UIImageView alloc]init];
		starImageView.frame = CGRectMake(12*i, 0, 10, 10);
		starImageView.image = [UIImage imageNamed:@"star_empty.png"];
		starImageView.tag = i+1;
		[_starBaseView addSubview:starImageView];
	}
	/**
	 观看次数
	 */
	_viewLabel = [[UILabel alloc]init];
	_viewLabel.frame = RECT(_left_image.frame.origin.x+220, _title_Label.frame.origin.y+56, 60, 12);
//	_viewLabel.text = @"1890人观看";
	_viewLabel.font = [UIFont systemFontOfSize:9];
	_viewLabel.textColor = [UIColor darkGrayColor];
	
	/**
	 箭头
	 */
	UIImageView *arrowImageView = [[UIImageView alloc]init];
	UIImage *arrowImage = [UIImage imageNamed:@"rightsign.png"];
	arrowImageView.frame = CGRectMake(SCREEN_WIDTH - 10 - 10, (94 - 15)/2, 10, 13);
	arrowImageView.image = arrowImage;
	
	
    [self addSubview:_left_image];
    [self addSubview:_title_Label];
    [self addSubview:_name_Label];
    [self addSubview:_teacher_Label];
	[self addSubview:_timeName_Label];
	[self addSubview:_time_Label];
	[self addSubview:_starBaseView];
	[self addSubview:_viewLabel];
	[self addSubview:arrowImageView];
}
-(void)setStarImageViewWithNumber:(NSString *)numStr;
{
	CGFloat num = numStr.floatValue;
	int fullNum = (int)num;
	BOOL isHalf = (CGFloat)(num - fullNum)>0.1?YES:NO;
	for (UIImageView *starIV in _starBaseView.subviews) {
		starIV.image = [UIImage imageNamed:@"star_empty.png"];
		if (starIV.tag<=fullNum) {
			starIV.image = [UIImage imageNamed:@"star_full.png"];
		}
		else if (starIV.tag == fullNum + 1 && isHalf) {
			starIV.image = [UIImage imageNamed:@"star_half.png"];
		}
	}
}
- (void)awakeFromNib
{
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}

@end
